//package com.example.common.widget
//
//import android.content.Context
//import android.graphics.Canvas
//import android.graphics.Color
//import android.graphics.Paint
//import android.util.AttributeSet
//import android.view.MotionEvent
//import android.view.View
//import com.example.common.tools.ColorUtil
//import com.example.common.tools.DensityUtil
//import com.example.common.tools.LogUtils
//import com.example.pulverizer.R
//
//
//class SelectProgress : View {
//
//    private val colorZC = ColorUtil.getColor(R.color.view_zc)
//    private val colorYJ = ColorUtil.getColor(R.color.view_yj)
//    private val colorGJ = ColorUtil.getColor(R.color.view_gj)
//    private val colorYZ = ColorUtil.getColor(R.color.view_yz)
//    private val colorDots = ColorUtil.getColor(R.color.view_dots)
//    private val colorTx = ColorUtil.getColor(R.color.text_gray)
//
//
//    //灰色背景线段的画笔
//    private var bgPaint: Paint? = null
//
//    //文字画笔
//    private var txPaint: Paint? = null
//    private var txPaint2: Paint? = null
//
//    //圆点画笔
//    private var dotsPaint: Paint? = null
//    private var dotsPaint2: Paint? = null
//    private var dotsPaintBig: Paint? = null
//
//    //实际进度绿色线段的画笔
//    private var progressPaint: Paint? = null
//
//    //进度条的最大宽度
//    private var maxProgress = 0f
//
//    //进度条当前的宽度
//    private var currentProgress = 0f
//
//    //当前View的宽度
//    private var mWidth = 0
//
//    //当前View的高度
//    private var mHeight = 0
//
//    //距离左边的内边距
//    private var mPaddingLeft = 0
//
//    //距离右边的内边距
//    private var mPaddingRight = 0
//
//    //进度条的位置
//    private var yHeight = 0f
//
//    private var warningX = 0f
//    private var alertX = 0f
//    private var seriousX = 0f
//    private var type: Int = 0
//
//    constructor(context: Context) : super(context) {
//
//    }
//
//    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
//        initPaint()
//    }
//
//    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
//        initPaint()
//    }
//
//    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
//    }
//
//    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
//        super.onLayout(changed, left, top, right, bottom)
//        mWidth = width//view的宽度
//        mHeight = height//view的高度
//        mPaddingRight = paddingRight  //距离右边的距离
//        mPaddingLeft = paddingLeft + DensityUtil.dip2px(context!!, 12f).toInt()//距离左边的距离
//        //最大进度长度等于View的宽度-(左边的内边距+右边的内边距)
//        maxProgress = (width - paddingLeft - paddingRight).toFloat()
//        yHeight = height / 2.toFloat() - DensityUtil.dip2px(context!!, 10f)
//    }
//
//    override fun onDraw(canvas: Canvas?) {
//        super.onDraw(canvas)
//        //绘制背景线段
//        //从（左边距，View高度的一半）开始，到（View宽度-右边距，View高度的一半）之间绘制灰色背景线段
//        canvas!!.drawLine(mPaddingLeft.toFloat(), yHeight, width - mPaddingRight.toFloat(),
//                yHeight, bgPaint!!)
//        //绘制实际进度线段
//        //从（左边距，View高度的一半）开始，到（现在的触摸到的进度宽度，View高度的一半）之间绘制绿色实际进度线段
//        canvas!!.drawLine(mPaddingLeft.toFloat(), yHeight, currentProgress,
//                yHeight, progressPaint!!)
//
//        //计算圆点位置
//        var firstX = paddingLeft.toFloat() + DensityUtil.dip2px(context!!, 7.2f)
//        var firstY = yHeight
//        var secondX = ((width - mPaddingRight) / 2).toFloat() - DensityUtil.dip2px(context!!, 30f)
//        var secondY = yHeight
//        var thirdX = ((width - mPaddingRight) / 2).toFloat() + DensityUtil.dip2px(context!!, 30f)
//        var thirdY = yHeight
//        var fourthX = (width - mPaddingRight).toFloat() - DensityUtil.dip2px(context!!, 5f)
//        var fourthY = yHeight
//        warningX = secondX
//        alertX = thirdX
//        seriousX = fourthX
//        LogUtils.eLog("view", "firstX = $firstX  secondX = $secondX")
//
//        //字体的距离
//        var firstTsX = firstX - DensityUtil.dip2px(context!!, 6f)
//        var firstTsY = firstY + DensityUtil.dip2px(context!!, 30f)
//        var secondTsX = secondX - DensityUtil.dip2px(context!!, 6f)
//        var secondTsY = secondY + DensityUtil.dip2px(context!!, 30f)
//        var thirdTsX = thirdX - DensityUtil.dip2px(context!!, 6f)
//        var thirdTsY = thirdY + DensityUtil.dip2px(context!!, 30f)
//        var fourthTsX = fourthX - DensityUtil.dip2px(context!!, 20f)
//        var fourthTsY = fourthY + DensityUtil.dip2px(context!!, 30f)
//        //字体间距
//        var txSpace = DensityUtil.dip2px(context!!, 15f)
//        //绘制一组点，坐标一一对应
//        when (type) {
//            0 -> {
//                canvas.drawPoint(firstX, firstY, dotsPaintBig!!)
//                canvas.drawPoint(secondX, secondY, dotsPaint!!)
//                canvas.drawPoint(thirdX, thirdY, dotsPaint!!)
//                canvas.drawPoint(fourthX, fourthY, dotsPaint!!)
//                canvas.drawText("正", firstTsX, firstTsY, txPaint2!!)
//                canvas.drawText("常", firstTsX, firstTsY + txSpace, txPaint2!!)
//                canvas.drawText("预", secondTsX, secondTsY, txPaint!!)
//                canvas.drawText("警", secondTsX, secondTsY + txSpace, txPaint!!)
//                canvas.drawText("告", thirdTsX, thirdTsY, txPaint!!)
//                canvas.drawText("警", thirdTsX, thirdTsY + txSpace, txPaint!!)
//                canvas.drawText("严重", fourthTsX, fourthTsY, txPaint!!)
//                canvas.drawText("告警", fourthTsX, fourthTsY + txSpace, txPaint!!)
//
//            }
//            1 -> {
//                canvas.drawPoint(firstX, firstY, dotsPaint2!!)
//                canvas.drawPoint(secondX, secondY, dotsPaintBig!!)
//                canvas.drawPoint(thirdX, thirdY, dotsPaint!!)
//                canvas.drawPoint(fourthX, fourthY, dotsPaint!!)
//                canvas.drawText("正", firstTsX, firstTsY, txPaint!!)
//                canvas.drawText("常", firstTsX, firstTsY + txSpace, txPaint!!)
//                canvas.drawText("预", secondTsX, secondTsY, txPaint2!!)
//                canvas.drawText("警", secondTsX, secondTsY + txSpace, txPaint2!!)
//                canvas.drawText("告", thirdTsX, thirdTsY, txPaint!!)
//                canvas.drawText("警", thirdTsX, thirdTsY + txSpace, txPaint!!)
//                canvas.drawText("严重", fourthTsX, fourthTsY, txPaint!!)
//                canvas.drawText("告警", fourthTsX, fourthTsY + txSpace, txPaint!!)
//            }
//            2 -> {
//                canvas.drawPoint(firstX, firstY, dotsPaint2!!)
//                canvas.drawPoint(secondX, secondY, dotsPaint2!!)
//                canvas.drawPoint(thirdX, thirdY, dotsPaintBig!!)
//                canvas.drawPoint(fourthX, fourthY, dotsPaint!!)
//                canvas.drawText("正", firstTsX, firstTsY, txPaint!!)
//                canvas.drawText("常", firstTsX, firstTsY + txSpace, txPaint!!)
//                canvas.drawText("预", secondTsX, secondTsY, txPaint!!)
//                canvas.drawText("警", secondTsX, secondTsY + txSpace, txPaint!!)
//                canvas.drawText("告", thirdTsX, thirdTsY, txPaint2!!)
//                canvas.drawText("警", thirdTsX, thirdTsY + txSpace, txPaint2!!)
//                canvas.drawText("严重", fourthTsX, fourthTsY, txPaint!!)
//                canvas.drawText("告警", fourthTsX, fourthTsY + txSpace, txPaint!!)
//            }
//            3 -> {
//                canvas.drawPoint(firstX, firstY, dotsPaint2!!)
//                canvas.drawPoint(secondX, secondY, dotsPaint2!!)
//                canvas.drawPoint(thirdX, thirdY, dotsPaint2!!)
//                canvas.drawPoint(fourthX - 8, fourthY, dotsPaintBig!!)
//                canvas.drawText("正", firstTsX, firstTsY, txPaint!!)
//                canvas.drawText("常", firstTsX, firstTsY + txSpace, txPaint!!)
//                canvas.drawText("预", secondTsX, secondTsY, txPaint!!)
//                canvas.drawText("警", secondTsX, secondTsY + txSpace, txPaint!!)
//                canvas.drawText("告", thirdTsX, thirdTsY, txPaint!!)
//                canvas.drawText("警", thirdTsX, thirdTsY + txSpace, txPaint!!)
//                canvas.drawText("严重", fourthTsX, fourthTsY, txPaint2!!)
//                canvas.drawText("告警", fourthTsX, fourthTsY + txSpace, txPaint2!!)
//            }
//        }
//        var percentY = mHeight / 4.toFloat()
//        canvas.drawText("20%", secondTsX - DensityUtil.dip2px(context!!, 5f), percentY, txPaint!!)
//        canvas.drawText("10%", thirdTsX - DensityUtil.dip2px(context!!, 5f), percentY, txPaint!!)
//
//    }
//
//    private fun initPaint() {
//
//        //进度条背景画笔
//        bgPaint = Paint()
//        bgPaint!!.color = Color.parseColor("#F0F0F0") //灰色
//        bgPaint!!.style = Paint.Style.FILL_AND_STROKE //填充且描边
//        bgPaint!!.isAntiAlias = true //抗锯齿
//        bgPaint!!.strokeCap = Paint.Cap.ROUND //线冒的头是圆的
//        bgPaint!!.strokeWidth = DensityUtil.dip2px(context!!, 5f) //大小为3dp转px
//
//        //默认圆点画笔
//        dotsPaint = Paint()
//        dotsPaint!!.style = Paint.Style.FILL_AND_STROKE //填充且描边
//        dotsPaint!!.color = colorDots!!
//        dotsPaint!!.isAntiAlias = true //抗锯齿
//        dotsPaint!!.strokeCap = Paint.Cap.ROUND //线冒的头是圆的
//        dotsPaint!!.strokeWidth = DensityUtil.dip2px(context!!, 10f) //大小为3dp转px
//        //
//        dotsPaint2 = Paint()
//        dotsPaint2!!.style = Paint.Style.FILL_AND_STROKE //填充且描边
//        dotsPaint2!!.isAntiAlias = true //抗锯齿
//        dotsPaint2!!.strokeCap = Paint.Cap.ROUND //线冒的头是圆的
//        dotsPaint2!!.strokeWidth = DensityUtil.dip2px(context!!, 10f) //大小为3dp转px
//
//        //加大圆点画笔
//        dotsPaintBig = Paint()
//        dotsPaintBig!!.style = Paint.Style.FILL_AND_STROKE //填充且描边
//        dotsPaintBig!!.isAntiAlias = true //抗锯齿
//        dotsPaintBig!!.strokeCap = Paint.Cap.ROUND //线冒的头是圆的
//        dotsPaintBig!!.strokeWidth = DensityUtil.dip2px(context!!, 15f) //大小为3dp转px
//
//        //设置进度画笔
//        progressPaint = Paint()
//        progressPaint!!.style = Paint.Style.FILL_AND_STROKE //填充且描边
//        progressPaint!!.isAntiAlias = true //抗锯齿
//        progressPaint!!.strokeCap = Paint.Cap.ROUND //线冒的头是圆的
//        progressPaint!!.strokeWidth = DensityUtil.dip2px(context!!, 5f) //大小为3dp转px
//
//        //绘制文字
//        txPaint = Paint()
//        txPaint!!.color = colorTx!! //灰色
//        txPaint!!.isFakeBoldText = true
//        txPaint!!.textSize = DensityUtil.dip2px(context!!, 12f)
//        txPaint2 = Paint()
//        txPaint2!!.isFakeBoldText = true
//        txPaint2!!.textSize = DensityUtil.dip2px(context!!, 12f)
//        invalidColor()
//    }
//
//    private fun invalidColor() {
//        when (type) {
//            0 -> {
//                progressPaint!!.color = colorZC!! //绿色
//                dotsPaintBig!!.color = colorZC!!
//                dotsPaint2!!.color = colorZC!!
//                txPaint2!!.color = colorZC!!
//            }
//            1 -> {
//                progressPaint!!.color = colorYJ!!
//                dotsPaintBig!!.color = colorYJ!!
//                dotsPaint2!!.color = colorYJ!!
//                txPaint2!!.color = colorYJ!!
//            }
//            2 -> {
//                progressPaint!!.color = colorGJ!!
//                dotsPaintBig!!.color = colorGJ!!
//                dotsPaint2!!.color = colorGJ!!
//                txPaint2!!.color = colorGJ!!
//            }
//            3 -> {
//                progressPaint!!.color = colorYZ!!
//                dotsPaintBig!!.color = colorYZ!!
//                dotsPaint2!!.color = colorYZ!!
//                txPaint2!!.color = colorYZ!!
//            }
//        }
//
//    }
//
//    override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
//        var y = event!!.y
//        var value = DensityUtil.px2dip(context,Math.abs(y - yHeight))
//        LogUtils.eLog("dispatchTouchEvent", "----------->${value}")
//        if (value < 30) {
//            parent.requestDisallowInterceptTouchEvent(true)
//        } else {
//            parent.requestDisallowInterceptTouchEvent(false)
//        }
//        return super.dispatchTouchEvent(event)
//    }
//
//    override fun onTouchEvent(event: MotionEvent?): Boolean {
//        var y = event!!.y
//        var value = DensityUtil.px2dip(context,Math.abs(y - yHeight))
//        if (value < 20) {
//            when (event!!.action) {
//                MotionEvent.ACTION_DOWN -> {
//                    //设置进度值
//                    setMotionProgress(event)
//                }
//                MotionEvent.ACTION_MOVE -> {
//                    //设置进度值
//                    setMotionProgress(event)
//                }
//            }
//        }
//        return true
//    }
//
//    //设置进度值
//    private fun setMotionProgress(event: MotionEvent) {
//        //获取当前触摸点，赋值给当前进度
//        currentProgress = event.x
//        LogUtils.eLog("view", "currentProgress = $currentProgress ")
//        //如果当前进度小于左边距
//        if (currentProgress < mPaddingLeft) {
//            currentProgress = paddingLeft.toFloat()
//        } else if (currentProgress > width - mPaddingRight) {
//            currentProgress = (width - mPaddingRight).toFloat()
//        }
//        if (currentProgress >= warningX && currentProgress < alertX) {
//            type = 1
//        } else if (currentProgress >= alertX && currentProgress < seriousX) {
//            type = 2
//        } else if (currentProgress >= seriousX) {
//            type = 3
//        } else {
//            type = 0
//        }
//        invalidColor()
//        invalidate()
//    }
//}

